board=[[1,2,3],[4,5,6],[7,8,9]]

def re_print(board):
    h=len(board)
    w=len(board[0])
    edge=[0,h,1,w] #上下左右
    d=1 #上下左右
    i=0
    x=0
    y=0
    while i<w*h-2:
        if d==0:
            while x>edge[0]:
                print(board[x][y])
                x-=1
                i+=1
            x+=1
            y-=1
            edge[0]+=1
            d=2
        elif d==1:
            while x<edge[1]:
                print(board[x][y])
                x+=1
                i+=1
            x-=1
            y+=1
            edge[1]-=1
            d=3
        elif d==2:
            while y>edge[2]:
                print(board[x][y])
                y-=1
                i+=1
            y+=1
            x+=1
            edge[2]+=1
            d=1
        else:
            while y<edge[3]:
                print(board[x][y])
                y+=1
                i+=1
            y-=1
            x-=1
            edge[3]-=1
            d=0

re_print(board)